<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // https://leetcode-cn.com/problems/intersection-of-two-arrays-ii/
        // 目前思路是先排序，然后双指针慢慢比较
        var intersect = function(nums1, nums2) {
            nums1.sort((a, b) => {
                return a - b;
            });
            nums2.sort((a, b) => {
                return a - b;
            })
            let p = 0;
            let q = 0;
            let nums3 = [];
            while (p < nums1.length && q < nums2.length) {
                if (nums1[p] < nums2[q]) {
                    p++;
                } else if (nums1[p] > nums2[q]) {
                    q++;
                } else {
                    nums3.push(nums1[p]);
                    p++;
                    q++;
                }
            }
            return nums3;
        };
        console.log(intersect([4,9,5], [9,4,9,8,4]));
    </script>
</body>
</html>